﻿//-----------------------------------------------------------------------
// <copyright file="PackageTest.cs" company="FastNET Services">
//     Copyright (c) 2008-2009. All Rights Reserved.
// </copyright>
// <license>
//     GPLv2
// </license>
// <warranty>
//     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
//     BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
//     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
//     DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// </warranty>
//-----------------------------------------------------------------------
#region Usings
using System;
using FastNET.CleanAct.Common.Repository.Interfaces.DataInterfaces.ManagementEngine;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Package = FastNET.CleanAct.Client.ManagerEngineData.Entities.Package;
#endregion

namespace FastNET.CleanAct.Testing.Client.ManagerEngineData.Entities
{
    /// <summary>
    /// Unit Tests for PackageTest
    /// </summary>
    [TestClass]
    public class PackageTest
    {
        /// <summary>
        /// Gets or sets the test context which provides
        /// information about and functionality for the current test run.
        /// </summary>
        public TestContext TestContext { get; set; }

        #region Name Validation

        /// <summary>
        /// Test for Name being Null
        /// </summary>
        [TestMethod]
        [ExpectedException(typeof(ArgumentNullException))]
        public void Name_Null()
        {
            new Package { Name = null };
        }

        /// <summary>
        /// Test for Name being Too Long
        /// </summary>
        [TestMethod]
        [ExpectedException(typeof(ArgumentOutOfRangeException))]
        public void Name_TooLong()
        {
            new Package { Name = string.Empty.PadRight(256, 'A') };
        }

        /// <summary>
        /// Test for Name being successful
        /// </summary>
        [TestMethod]
        public void Name_Success()
        {
            IPackageData data = new Package { Name = "TestName" };
            Assert.AreEqual("TestName", data.Name, "Mismatched Data");
        }

        /// <summary>
        /// Test for Name being defaulted
        /// </summary>
        [TestMethod]
        public void Name_Default()
        {
            IPackageData data = new Package();
            Assert.AreEqual(null, data.Name, "Mismatched Data");
        }

        #endregion

        #region Publisher Validation

        /// <summary>
        /// Test for Publisher being Null
        /// </summary>
        [TestMethod]
        public void Publisher_Null()
        {
            new Package { Publisher = null };
        }

        /// <summary>
        /// Test for Publisher being Too Long
        /// </summary>
        [TestMethod]
        [ExpectedException(typeof(ArgumentOutOfRangeException))]
        public void Publisher_TooLong()
        {
            new Package { Publisher = string.Empty.PadRight(256, 'A') };
        }

        /// <summary>
        /// Test for Publisher being successful
        /// </summary>
        [TestMethod]
        public void Publisher_Success()
        {
            IPackageData data = new Package { Publisher = "TestName" };
            Assert.AreEqual("TestName", data.Publisher, "Mismatched Data");
        }

        /// <summary>
        /// Test for Publisher being defaulted
        /// </summary>
        [TestMethod]
        public void Publisher_Default()
        {
            IPackageData data = new Package();
            Assert.AreEqual(null, data.Publisher, "Mismatched Data");
        }

        #endregion

        #region DateCreated Validation

        /// <summary>
        /// Test for DateCreated being successful
        /// </summary>
        [TestMethod]
        public void DateCreated_Success()
        {
            DateTime newDate = DateTime.UtcNow;
            IPackageData data = new Package { DateCreated = newDate };
            Assert.AreEqual(newDate, data.DateCreated, "Mismatched Data");
        }

        /// <summary>
        /// Test for DateCreated being defaulted
        /// </summary>
        [TestMethod]
        public void DateCreated_Default()
        {
            IPackageData data = new Package();
            Assert.AreEqual(DateTime.MinValue, data.DateCreated, "Mismatched Data");
        }

        #endregion

        #region Version Validation

        /// <summary>
        /// Test for Version being Null
        /// </summary>
        [TestMethod]
        [ExpectedException(typeof(ArgumentNullException))]
        public void Version_Null()
        {
            new Package { Version = null };
        }

        /// <summary>
        /// Test for Version being Too Long
        /// </summary>
        [TestMethod]
        [ExpectedException(typeof(ArgumentOutOfRangeException))]
        public void Version_TooLong()
        {
            new Package { Version = string.Empty.PadRight(21, 'A') };
        }

        /// <summary>
        /// Test for Version being successful
        /// </summary>
        [TestMethod]
        public void Version_Success()
        {
            IPackageData data = new Package { Version = "5.0.0.0" };
            Assert.AreEqual("5.0.0.0", data.Version.ToString(), "Mismatched Data");
        }

        /// <summary>
        /// Test for Version being defaulted
        /// </summary>
        [TestMethod]
        public void Version_Default()
        {
            IPackageData data = new Package();
            Assert.AreEqual(null, data.Version, "Mismatched Data");
        }

        #endregion
    }
}
